//
//  ThirteenViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/4/10.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class ThirteenViewController: UIViewController {

    fileprivate lazy var mutDataArr:NSMutableArray = {
        var mutArr = NSMutableArray();
        mutArr.add("Koloda");
        return mutArr;
    }();
    fileprivate let cellID = "thirtenn_cellID";
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "相册选择器";
        self.view.backgroundColor = .white;
        // Do any additional setup after loading the view.
        self.onCreateUIForNavigation();
        self.onCreateUIForView();
    }
    

    //TODO:UI
    fileprivate func onCreateUIForNavigation() {
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", style: .plain, target: self, action: #selector(onBack));
    }
    
    fileprivate func onCreateUIForView() {
        let tableView = UITableView(frame: CGRect(x: 0, y: 0, width: screenMainSize.width, height: screenMainSize.height), style: .plain);
        tableView.backgroundColor = .clear;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellID);
        self.view.addSubview(tableView);
    }
    
    //MARK:Actions
    @objc fileprivate func onBack() {
        self.navigationController?.dismiss(animated: true, completion: nil);
    }
}

extension ThirteenViewController:UITableViewDelegate {
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if mutDataArr.count > indexPath.row {
            switch indexPath.row {
            case 0:
                let vc = ThirteenOneViewController();
                self.navigationController?.pushViewController(vc, animated: true);
                break;
           
            default:
                break;
            }
        }
    }
}

extension ThirteenViewController:UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.mutDataArr.count;
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID);
        
        if self.mutDataArr.count > indexPath.row {
            cell?.textLabel?.text = (self.mutDataArr[indexPath.row] as! String);
        }
        
        return cell!;
    }
}
